/*
 * @Author: Crism
 * @Date: 2018-10-31 09:58:30
 * @LastEditors: Crism
 * @LastEditTime: 2018-11-22 16:53:39
 * @Email: crism@qq.com
 * @Description: 
 */

const db_user = require('../config').db_user;

/** 设置用户头像和姓名 */
module.exports.set_albums_user_name_and_img = set_albums_user_name_and_img;
async function set_albums_user_name_and_img(albums) {
    let owner_id = db_user.escape(albums['owner_id']);
    let sql = 'select user_name,image_id from ty_user where ty_id=' + owner_id;
    let user_info = await db_user.queryOne(sql);
    if (user_info != null) {
        albums['owner_name'] = user_info['user_name'];
        albums['owner_img'] = user_info['image_id'];
    } else {
        albums['owner_name'] = '佚名';
        albums['owner_img'] = 123;
    }
    return albums;
}

/** 查询用户头像和姓名 */
module.exports.get_user_name_and_img = get_user_name_and_img;
async function get_user_name_and_img(owner_id) {
    owner_id = db_user.escape(owner_id);
    let sql = 'select user_name,image_id from ty_user where ty_id=' + owner_id;
    let user_info = await db_user.queryOne(sql);
    if (user_info != null) {
        return [user_info['user_name'], user_info['image_id']];
    }
    return [null, null];
}